//
//  FunPicTableViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/5/9.
//

#import "FunPicTableViewCell.h"
#import "ReportViewController.h"
@implementation FunPicTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self.contentView.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(50);
            make.left.equalTo(self.contentView).offset(12);
        make.top.equalTo(self.contentView).offset(16);
    }];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.centerY.equalTo(self.headerView).offset(-8);
    }];
    [self.contentView addSubview:self.sexImage];
    [self.sexImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.nameLabel.mas_right).offset(6);
    }];
    [self.contentView addSubview:self.rzImage];
    [self.rzImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.sexImage.mas_right).offset(6);
    }];
    
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(4);
    }];
    
    [self.contentView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14);
            make.right.equalTo(self.contentView.mas_right).offset(-14);
            make.top.equalTo(self.headerView.mas_bottom).offset(12);
    }];
    
    [self.contentView addSubview:self.bgImage];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.messageLabel.mas_bottom).offset(12);
        make.height.mas_equalTo((SCREEN_WIDETH-28)*0.618);
    }];
   
    
    [self.contentView addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(40);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
            make.centerY.equalTo(self.headerView);
    }];
   
    
    WS(weakSelf);
    [self.rightBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        NSArray * array = @[@"举报",@"拉黑"];
     YBPopupMenu * pop =  [YBPopupMenu showRelyOnView:button titles:array icons:@[@"jubao",@"lahei"] menuWidth:120 otherSettings:^(YBPopupMenu *popupMenu) {
        
        }];
        pop.offset = 40;
        pop.delegate = weakSelf;
    }];
    
     
    self.FS_cellBottomView = self.bgImage;
    
}

- (void)setModel:(FunyModel *)model{
    _model = model;
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    self.nameLabel.text = model.name;
    if ([model.uid isEqualToString:[UserModel share].userid]) {
        [self.headerView.headerImage sd_setImageWithURL:SQURLImage([UserModel share].portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
        self.nameLabel.text = [UserModel share].name;
    }
    self.timeLabel.text = model.createTime;
    self.messageLabel.text = model.content;
    if ([model.imgs isNotEmpty]) {
        NSArray * array = [model.imgs componentsSeparatedByString:@","];
         self.bgImage.imageArray = [NSMutableArray arrayWithArray:array];
        self.bgImage.model = self.model;
        self.bgImage.isDetaile = self.isDetaile;
    }
   
    
    if (model.gender ==1) {
        self.sexImage.image = SQGetImage(@"男");
    } else {
        self.sexImage.image = SQGetImage(@"女");
    }
    if (model.realStatus == 2) {
        self.rzImage.image = SQGetImage(@"认证");
    } else {
        self.rzImage.image = SQGetImage(@"未认证");
    }
}
- (void)setIsDetaile:(BOOL)isDetaile{
    _isDetaile = isDetaile;
    if (isDetaile) {
       self.rightBtn.hidden = YES;
    } else {
       self.rightBtn.hidden = NO;
        if ([self.model.uid isEqualToString:[UserModel share].userid]) {
            self.rightBtn.hidden = YES;
        }else{
            self.rightBtn.hidden = NO;
        }
    }
    
}

- (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index{
    if (index ==0) {
        //举报
        ReportViewController * vc = [[ReportViewController alloc]init];
        vc.userid = self.model.userid;
        vc.type = @"1";
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    } else {
        if (self.isBlackBlock) {
            self.isBlackBlock();
        }
    }
}
- (UIImageView *)rzImage{
    if (!_rzImage) {
        _rzImage = [[UIImageView alloc]init];
        _rzImage.image = SQGetImage(@"已认证");
        _rzImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _rzImage;
}
- (UIImageView *)sexImage{
    if (!_sexImage) {
        _sexImage = [[UIImageView alloc]init];
        _sexImage.image = SQGetImage(@"男");
        _sexImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _sexImage;
}
 

-(void)SQ_headerViewButtonClick{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = self.model.uid;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

- (FunImageBgView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[FunImageBgView alloc]init];
        _bgImage.clipsToBounds = YES;
        _bgImage.layer.masksToBounds = YES;
        _bgImage.backgroundColor = UIColor.clearColor;
    }
    return _bgImage;
}
- (SQCustomButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(30, 20) midmargin:0];
        _rightBtn.image = SQGetImage(@"shanchu");
        _rightBtn.layer.cornerRadius = 4;
        _rightBtn.layer.masksToBounds = YES;
       
    }
    return _rightBtn;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = UIColor.whiteColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(12);
        _timeLabel.textColor = SQColor(@"#D3D3D3");
        _timeLabel.backgroundColor = UIColor.clearColor;
    }
    return _timeLabel;
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_headerViewButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _headerView.layer.cornerRadius = 25;
        _headerView.layer.masksToBounds = YES;
    }
    return _headerView;
}
- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_REGULAR(14);
        _messageLabel.textColor = UIColor.whiteColor;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}

 
@end
